package com.llly.controller;

import com.github.pagehelper.Page;
import com.llly.pojo.Easybuy_order;
import com.llly.pojo.Easybuy_product;
import com.llly.pojo.Easybuy_product_category;
import com.llly.service.BackstageProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
public class BackstageProductController {
    @Autowired
    private BackstageProductService backstageproductservice;

    //管理页面，分类管理，查询
    @RequestMapping("/Allproductcategory")
    public Map<String,Object> Allproduct_category(@RequestParam Integer PageIndex) {
        Page<Map<String, Object>> maps = backstageproductservice.Allproduct_category(PageIndex);
        Map map=new HashMap();
        map.put("Result",maps.getResult());
        map.put("Total",maps.getTotal());
        map.put("PageNum",maps.getPageNum());
        map.put("Pages",maps.getPages());
        return map;
    }

    //管理页面，分类管理，查询2
    @RequestMapping("/Allproduct_category2")
    public List<Map<String, Object>> Allproduct_category2() {
        return backstageproductservice.Allproduct_category2();
    }

    //管理页面，分类管理，查询有无商品
    @RequestMapping("/ideasybuy_product")
    public int ideasybuy_product(@RequestParam Integer id) {
        return backstageproductservice.ideasybuy_product(id);
    }


    //管理页面，分类管理，删除
    @RequestMapping("/deleteproductcategory")
    public int deleteproductcategory(@RequestParam Integer id) {
        return backstageproductservice.deleteproductcategory(id);
    }

    //管理员页面，分类管理，新增
    @RequestMapping("/addproductcategory")
    public int addproductcategory(@RequestParam String name,@RequestParam Integer type,@RequestParam Integer parentId) {
        return backstageproductservice.addproductcategory(name,type,parentId);
    }

    //管理页面，商品管理，查询
    @RequestMapping("/Alleasybuy_product")
    public Map<String,Object> Alleasybuy_product(@RequestParam Integer PageIndex) {
        Page<Easybuy_product> allproduct = backstageproductservice.Alleasybuy_product(PageIndex);
        Map map=new HashMap();
        map.put("Result",allproduct.getResult());
        map.put("Total",allproduct.getTotal());
        map.put("PageNum",allproduct.getPageNum());
        map.put("Pages",allproduct.getPages());
        return map;
    }
    //管理员页面,商品管理，修改
    @RequestMapping("/updateproduct")
    public int updateproduct(@RequestBody Easybuy_product ep){
        return backstageproductservice.updateproduct(ep);
    }

    //管理员页面,商品管理，id查询，修改的回显
    @RequestMapping("/idproduct")
    public List<Easybuy_product> idproduct(@RequestParam Integer id){
        System.out.println("ididididdidididid"+id);
        return backstageproductservice.idproduct(id);
    }

    //管理页面，商品管理，删除
    @RequestMapping("/deleteproduct")
    public int deleteproduct(@RequestParam Integer id) {
        return  backstageproductservice.deleteproduct(id);
    }

}
